{extend name=".././view/list.html" /}
{block name="jsset"}
{/block}
{block name="nav"}
<span class="layui-breadcrumb">
	<a href="">师生名单</a>
	<a href="">学生管理</a>
	<a><cite>学生列表</cite></a>
</span>
{/block}
{block name="search"}
<div class="layui-form-item">
	<label for="searchval" class="layui-form-label">
		关键字
	</label>
	<div class="layui-input-block">
		<input type="text" id="searchval" name="searchval" autocomplete="off" class="layui-input" placeholder="输入关键字并回车">
	</div>
</div>
<div class="layui-form-item">
	<label for="school_id" class="layui-form-label">学校</label>
	<div class="layui-input-block">
		<select name="school_id" id="school_id">
		</select>
	</div>
</div>
<div class="layui-form-item">
	<label for="ruxuenian" class="layui-form-label">年级</label>
	<div class="layui-input-block">
		<select id="ruxuenian" name="ruxuenian">
		</select>
	</div>
</div>
<div class="layui-form-item" style="margin-bottom: 0;">
	<label for="banji_id" class="layui-form-label" style="height: 100%">班级</label>
	<div class="layui-input-block" id="banji_id">
	</div>
</div>
<div class="layui-form-item" style="text-align: right;">
	<button class="layui-btn" lay-filter="searchSubmit" lay-submit="">搜索</button>
</div>
{present name="list.banji_id"}
<input type="hidden" name="banji_id[]" value="{$list.banji_id}">
{/present}
{/block}
{block name="table"}
<table id="tabledemo" lay-filter="mytable" lay-size="sm"></table>
{/block}
{block name="myjs"}
<!-- 表格上面按钮模板 -->
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-danger" lay-event="dels">
			<i class="iconfont">&#xe69d;</i> 批量删除
		</button>
		<button class="layui-btn" lay-event="add">
			<i class="iconfont">&#xe6b9;</i> 添加
		</button>
		<button class="layui-btn" lay-event="upload">
			<i class="iconfont">&#xe71d;</i> 校对导入
		</button>
		<button class="layui-btn" lay-event="download">
			<i class="iconfont">&#xe714;</i> 下载模板
		</button>
		<button class="layui-btn" lay-event="jdsc">
			<i class="iconfont">&#xe714;</i> 表格删除
		</button>
	</div>
</script>
<script type="text/html" id="kaoshi">
	<input type="checkbox" myurl="{$list.kaoshi ? $list.kaoshi : url('kaoshi')}" {{d.kaoshi == "参加" ? "checked" :""}} id="{{d.id}}" lay-skin="switch" lay-filter="kaoshi" lay-text="参加|不参加">
</script>
<!-- 记录操作按钮模板 -->
<script type="text/html" id="barDemo">
	<a class="layui-btn-xs" lay-event="detail" title="查看"><i class="layui-icon layui-icon-search"></i></a>
  <a class="layui-btn-xs" lay-event="chengji" title="成绩"><i class="layui-icon layui-icon-chart-screen"></i></a>
	<a class="layui-btn-xs" lay-event="edit" title="编辑"><i class="layui-icon layui-icon-edit"></i></a>
  <a class="layui-btn-xs" lay-event="reset" title="密码重置"><i class="layui-icon layui-icon-password"></i></a>
	<a class="layui-btn-xs" lay-event="del" title="删除"><i class="layui-icon">&#xe640;</i></a>
</script>
<!-- 表格操作 -->
<script>
// 提交搜索条件后重载表格
layui.use(['table', 'mytable', 'createInput', 'form'], function() {
	var table = layui.table,
		form = layui.form,
		cInput = layui.createInput,
		mytable = layui.mytable;

	cInput.schoolSelect('school_id', '校级', '校级');
	cInput.nanjiSelect('ruxuenian');

	// 设置列
	options.cols = [
		[ //表头
			{ type: 'checkbox', fixed: 'left' },
			{
				title: '学校',
				fixed: 'left', 
				width:70,
				templet: function(d) {
					var str = '';
					if (d.stuBanji) {
						if (d.stuBanji.glSchool) {
							if (d.stuBanji.glSchool.jiancheng) {
								d.stuBanji.glSchool.jiancheng;
							}
						}
						str = d.stuBanji.glSchool.jiancheng;
					}
					return str;
				}
			},
			{
				field: 'banji_id',
				title: '班级',
				sort: true,
				fixed: 'left', 
				templet: function(d) {
					var str = '';
					if (d.stuBanji) {
						str = d.stuBanji.banjiTitle;
					}
					return str;
				}
			},
			{ field: 'xingming', title: '姓名', minWidth:100, sort: true, fixed: 'left' },
			{ field: 'sex', title: '性别', sort: true, minWidth:100 },
			{
				field: "shengri",
				title: '周岁',
				sort: true,
				minWidth:100,
				templet: function(d) {
					return d.age;
				}
			},
			{ field: 'xuehao', title: '学号', minWidth:80, sort: true, edit: 'text'},
			{ field: 'status', title: '是否参加考试', templet: '#kaoshi', minWidth:80, sort: true },
			{ field: 'status', title: '状态', templet: '#status', minWidth:80, sort: true },
			{ field: 'id', title: '操作', toolbar: '#barDemo', minWidth: 180 }
		]
	];

	// 获取筛选条件并加载表格
	options.where = form.val("search");
	userTable = table.render(options); //获取数据并渲染

	//表头工具栏事件
	table.on('toolbar(mytable)', function(obj) {
		switch (obj.event) {
			case 'dels':
				var checkStatus = table.checkStatus('mytable'); //idmytable 即为基础参数 id 对应的值
				mytable.delAll(checkStatus, '/student/index/delete', 'mytable');
				break;
			case 'add':
				xadmin.open('添加学生', '/student/index/create', '', '', true);
				break;
			case 'upload':
				xadmin.open('校对导入', '/student/index/createall', '600', '300', false);
				break;
			case 'download':
				window.open("/student/index/download");
				break;
			case 'jdsc':
				xadmin.open('表格删除', '/student/index/deletes', '600', '300', false);
				break;
		};
	});

	//监听行工具条
	table.on('tool(mytable)', function(obj) {
		var data = obj.data; //获得当前行数据
		var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
		var tr = obj.tr; //获得当前行 tr 的DOM对象
		switch (layEvent) {
			case 'detail': // 查看
				parent.xadmin.add_tab(obj.data.xingming + '－信息', '/student/index/read/' + obj.data.id, true);
				break;
			case 'chengji': // 查看
				parent.xadmin.add_tab(obj.data.xingming + ' － 成绩', '/student/chengji/index/' + obj.data.id, true);
				break;
			case 'del': // 删除
				mytable.del(obj, "/student/index/delete");
				break;
			case 'edit': // 编辑
				xadmin.open('编辑学生', '/student/index/edit/' + obj.data.id, '', '', true);
				break;
			case 'status': // 状态
				mytable.status(obj, "{:url('setstatus')}");
				break;
			case 'reset': // 编辑
				mytable.resetpassword(obj.data.xingming, "/student/index/resetpassword/" + obj.data.id);
				break;
		};
	});

	form.on('select()', function(data) {
		data = form.val("search");
		if (data.school_id > 0 && data.ruxuenian > 0) {
			cInput.banjiCheckbox('banji_id', data);
		}
	});

	form.on('checkbox(mycheackbox)', function(data) {
		cInput.checkboxChecked(data);
	});

	// 单元格编辑
  table.on('edit(mytable)', function(obj) {
    // 声明变量
    var kaohao = obj.value,
      rowdata = obj.data;

    // 修改服务器数据
    $.ajax({
      url: "/student/index/onekaohao/" + rowdata.id,
      type: 'PUT',
      data: {
        "kaohao": kaohao
      },
      success: function(result, objs) {
        if (result.val == 0 || result.code == 0) {
          layer.msg(result.msg, { icon: 5 });
        } else {
          obj.update({
            val: kaohao
          });
        }
      },
      error: function(result) {
        layer.msg('数据扔半道啦。', function() {});
      },
    });
  });

});

</script>
{/block}
